#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/1/12 15:03
# @Author  : ldh

from airtest.core.api import *
from basic.device.Android import Android
from time import sleep
from basic.utils.h5View import H5View


class AGX_oclifePage(Android):
    ivCommItem="cn.cloudbae.loveguangxi:id/ivCommItem"  #应用
    refreshTxt="cn.cloudbae.loveguangxi:id/refreshTxt" #刷码文案
    qrcode_img="cn.cloudbae.loveguangxi:id/oc_qrcode_img" #二维码
    grid_icon="cn.cloudbae.loveguangxi:id/oc_grid_icon" #场景
    channel_name="cn.cloudbae.loveguangxi:id/channel_name" #更多场景-场景名
    topRightMenu="cn.cloudbae.loveguangxi:id/oc_topRightMenu" #更多功能“…”按钮
    menuBtm="cn.cloudbae.loveguangxi:id/trm_menu_item_text" #更多-子功能按钮
    bill="cn.cloudbae.loveguangxi:id/txtTL" #账单列表


    #打开一码八桂页
    @classmethod
    def openOclife(cls):
        cls.poco(cls.ivCommItem)[0].click()
        sleep(5)


    @classmethod
    def ifoclife(cls):
        if cls.poco(cls.refreshTxt).exists():
            return True
        else:
            return False


    #拉码校验
    @classmethod
    def qrcode(cls):
        if cls.poco(cls.qrcode_img).wait(3).exists():
            print("拉码正常！")
        else:
            exit()


    #场景校验
    @classmethod
    def channel(cls):
        if cls.poco(cls.grid_icon).exists():
            print("场景显示正常！")
        else:
            exit()


    #更多场景
    @classmethod
    def moreChannel(cls):
        cls.poco(cls.grid_icon)[4].click()
        sleep(3)


    #更多场景校验
    @classmethod
    def getChannelName(cls):
        channelname1 =cls.poco(cls.channel_name)
        list1=[]
        list2=[]
        for i in range(0,len(channelname1)):
            list1.append(channelname1[i].get_text())
        swipe((500, 2000),(500, 300))
        sleep(3)
        channelname2 = cls.poco(cls.channel_name)
        for n in range(2,len(channelname2)):
            list2.append(channelname2[n].get_text())
        list=list1+list2
        print("场景总数："+str(len(list)))
        print(list)
        return list


    #打开支付设置页
    @classmethod
    def openPayChannel(cls):
        cls.poco(cls.topRightMenu).click()
        cls.poco(cls.menuBtm)[1].click()
        sleep(3)


    @classmethod
    def getPayChannel(cls):
         payChannel=H5View.views(".*?免密支付设置")
         channelList=[]
         for i in range(0,len(payChannel)):
             channelList.append(payChannel[i].get_text())
         print(channelList)
         return channelList


    #打开账单记录
    @classmethod
    def openBillList(cls):
        cls.poco(cls.topRightMenu).click()
        cls.poco(cls.menuBtm)[2].click()
        sleep(10)


    @classmethod
    def ifBills(cls):
        if cls.poco(cls.bill).exists():
            return True
        else:
            return False

    @classmethod
    def billDetail(cls):
        cls.poco(cls.bill)[0].click()














